package Algorithm.Othes;

import java.util.LinkedList;
import java.util.List;
//https://leetcode-cn.com/problems/shuffle-an-array/
public class Leetcode384 {
    class Solution {
        private int[] temp;
        private int n;

        public Solution(int[] nums) {
            temp = new int[nums.length];
            for(int i=0;i<nums.length;i++){
                temp[i] = nums[i];
            }
            n = nums.length;
        }

        public int[] reset() {
            return temp;
        }

        public int[] shuffle() {
            List<Integer> list = new LinkedList<Integer>();
            for(int i=0;i<temp.length;i++){
                list.add(temp[i]);
            }

            int count = n;
            int[] result = new int[n];
            for(int i=0;i<temp.length;i++){
                int selectedIndex = (int)(Math.random()*count);
                // System.out.println(selectedIndex);
                result[i] = list.get(selectedIndex);
                list.remove(selectedIndex);
                count--;
            }

            return result;
        }
    }

/**
 * Your Solution object will be instantiated and called as such:
 * Solution obj = new Solution(nums);
 * int[] param_1 = obj.reset();
 * int[] param_2 = obj.shuffle();
 */
}
